﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Http;
using App.Composers;
using App.Domain.Model;
using App.Service.WebAPI.Resources;
using System.Collections.Specialized;
using System.Web;

namespace App.Service.WebAPI.Controllers
{
    public class LookupController : ControllerBase
    {
        public LookupResource GET(string secondLevel)
        {
            int ownerId;
            LookupResource lr = new LookupResource();
            switch (secondLevel.ToLower())
            {
                case "countries":
                    lr.LookUpItems = bal.GetCountries(QueryString["partialCountry"])
                        .Select(item => new LookupItem() { Key = item.CountryRegionCode, Value = item.Name })
                        .ToList();
                    break;
                case "states":
                    lr.LookUpItems = bal.GetStates(QueryString["countryCode"])
                        .Select(item => new LookupItem() { Key = item.StateProvinceCode, Value = item.Name })
                        .ToList();
                    break;
                case "contacttypes":
                    lr.LookUpItems = bal.ContactTypes
                        .Select(item => new LookupItem() { Key = item.ContactTypeID.ToString(), Value = item.Name })
                        .ToList();
                    break;
                case "addresstypes":
                    lr.LookUpItems = bal.AddressTypes
                        .Select(item => new LookupItem() { Key = item.AddressTypeID.ToString(), Value = item.Name })
                        .ToList();
                    break;
                case "roles":
                    lr.LookUpItems = bal.Roles
                        .Select(item => new LookupItem() { Key = item.RoleID.ToString(), Value = item.RoleName })
                        .ToList();
                    break;
                case "phonenumbers":
                    Int32.TryParse(QueryString["ownerId"], out ownerId);
                    lr.LookUpItems = bal.GetPhoneNumbers(QueryString["type"], ownerId)
                        .Select(item => new LookupItem() { Key = item, Value = item })
                        .ToList();
                    break;
                case "emails":
                    Int32.TryParse(QueryString["ownerId"], out ownerId);
                    lr.LookUpItems = bal.GetEmails(ownerId)
                        .Select(item => new LookupItem() { Key = item, Value = item })
                        .ToList();
                    break;
                case "phonenumbertypes":
                    lr.LookUpItems = bal.PhoneNumberTypes
                        .Select(item => new LookupItem() { Key = item.PhoneNumberTypeID.ToString(), Value = item.Name })
                        .ToList();
                    break;
                case "namestyles":
                    lr.LookUpItems = bal.NameStyles
                        .Select(item => new LookupItem() { Key = item.Key.ToString(), Value = item.Value })
                        .ToList();
                    break;
                case "emailpromotions":
                    lr.LookUpItems = bal.EmailPromotions
                        .Select(item => new LookupItem() { Key = item.Key.ToString(), Value = item.Value })
                        .ToList();
                    break;
                default:
                    break;
            }
            return lr;
        }
    }
}
